package nit.wave.utils;

import nit.wave.menu.Button;
import nit.wave.menu.CommonButton;
import nit.wave.menu.ComplexButton;
import nit.wave.menu.Menu;
import nit.wave.menu.ViewButton;
import nit.wave.model.AccessToken;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 菜单管理器类
 * 
 * @author taoshanchang
 */
public class MenuManager {
	private static Logger log = LoggerFactory.getLogger(MenuManager.class);

	public static void main(String[] args) {
		// 调用接口获取access_token
		AccessToken accessToken = WeixinUtil.getAccessToken();
System.out.println(accessToken.getToken());
		/*if (null != accessToken) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), accessToken.getToken());
			System.out.println(result);
			// 判断菜单创建结果
			if (0 == result)
				log.info("菜单创建成功！");
			else
				log.info("菜单创建失败，错误码：" + result);
		}*/
	}

	// 组装菜单数据
	private static Menu getMenu() {
		CommonButton libraryBt = new CommonButton();
		libraryBt.setName("图书馆");
		libraryBt.setType("click");
		libraryBt.setKey("library");

		CommonButton jwxtBt = new CommonButton();
		jwxtBt.setName("教务系统(开发中)");
		jwxtBt.setType("click");
		jwxtBt.setKey("jwxt");

		CommonButton waimaiBt = new CommonButton();
		waimaiBt.setName("外卖单");
		waimaiBt.setType("click");
		waimaiBt.setKey("waimai");

		CommonButton waveBt = new CommonButton();
		waveBt.setName("三江潮");
		waveBt.setType("click");
		waveBt.setKey("wave");

		ViewButton biaobaiBt = new ViewButton();
		biaobaiBt.setName("表白墙");
		biaobaiBt.setUrl("http://sanjiangchao.aliapp.com/biaobai/index.html");
		biaobaiBt.setType("view");

		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("微校园");
		mainBtn1.setSub_button(new Button[] { libraryBt, jwxtBt });

		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("玩转理工");
		mainBtn2.setSub_button(new Button[] { biaobaiBt });

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("三江潮");
		mainBtn3.setSub_button(new Button[] { waveBt });

		/**
		 * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br>
		 * 
		 * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br>
		 * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br>
		 * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 });
		 */
		Menu menu = new Menu();
		menu.setButton(new Button[] {mainBtn1, mainBtn2, mainBtn3 });

		return menu;
	}
}